<script>
	$(document).ready(function(){
        $('input[type="radio"]').click(function(){		
            if($(this).attr("value")=="baru"){
                $("div#baru").show('slow');
                $("div#lama").hide('slow');
                $("div#pindah").hide('slow');
            }
            if($(this).attr("value")=="lama"){
               $("div#lama").show('slow');
               $("div#baru").hide('slow');
               $("div#pindah").hide('slow');
            }
            if($(this).attr("value")=="pindah"){
               $("div#pindah").show('slow');
               $("div#baru").hide('slow');
               $("div#lama").hide('slow');
            }
        });
    });
</script>
<!-- Add Siswa Modal -->
<div class="modal fade" id="addSiswa" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Tambah Siswa</h4>
      </div>
      <div class="modal-body">
		<form class="form-horizontal" role="form">
		<div class="form-group">
		<label class="col-sm-3 control-label">Pilihan Siswa</label>
		<div class="col-sm-9">
			<label class="radio-inline">
				<input type="radio" name="pilih" value="baru" checked>
				Pembagian Kelas Siswa Baru
			</label>

			<label class="radio-inline">
				<input type="radio" name="pilih" value="lama">
				Kenaikan Kelas
			</label>

			<label class="radio-inline">
				<input type="radio" name="pilih" value="pindah">
				Perpindahan Kelas
			</label>
		</div>
	  </div>
	  </form>
	  
	  <div id="baru">
		<?php 
			echo form_open('bagi_kelas/add_exe', array('class' => 'form-horizontal', 'role' => 'form')); 
		?>
		<input type="hidden" name="id_atur_kelas" value="<?php echo $nis = $this->security->xss_clean($this->uri->segment(3));?>"/>					  
		
			<div class="form-group">
				<label class="col-sm-3 control-label">List Siswa</label>
				<div class="col-sm-9">
					<?php 
					if(count($list_siswa_baru)>0){
						foreach ($list_siswa_baru as $row_sb) {
					?>
					<div class="checkbox">
						<label>
							<input type="checkbox" name="nis[]" value="<?php echo $row_sb->nis; ?>"> <?php echo $row_sb->nis.' '.$row_sb->nm_lengkap; ?>
						</label>
					</div>
					<?php
							}
						}else{
						?>
						<div class="checkbox">
						<label>
							<input type="checkbox" disabled> Belum ada registrasi siswa baru
						</label>
						</div>
						<?php
						}
						?>
				</div>
			</div>
			
			<div class="modal-footer">
				<button class="btn btn-default btn-sm" data-dismiss="modal">Batal</button>
				<button type="submit" class="btn btn-primary btn-sm">Tambahkan</button>
			</div>
		<?php
			echo form_close();
		?>
		</div>
		
	  <div id="lama" style="display:none;">
		<?php 
			echo form_open_multipart('bagi_kelas/add_exe', array('class' => 'form-horizontal', 'role' => 'form')); 
		?>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">Kelas</label>
			<div class="col-sm-3">
				<select name="id_mr_kelas" id="kelas" class="form-control input-sm" <?php if(count($list_kelas)<1){echo "disabled";}?>>
					<option value="null">- Pilih Kelas -</option>
					<?php 
					if(count($list_kelas)>0){
						foreach ($list_kelas as $row_k){ ?>
						<option value="<?php echo $row_k->id_mr_kelas; ?>"><?php echo $row_k->kelas; ?></option>
					<?php 
						}
					}else{
					?>
						<option>Tidak ada data</option>
					<?php 
					}
					?>

				</select>
			</div>
			
			<label class="col-sm-2 control-label">Th. Ajaran</label>
			<div class="col-sm-4">
				<select name="id_mr_th_ajaran" id="tajar" class="form-control input-sm" <?php if(count($list_tajar)<1){echo "disabled";}?>>
					<option value="null">- Pilih Th. Ajaran -</option>
					<?php 
					if(count($list_kelas)>0){
						foreach ($list_tajar as $row_ta){ ?>
						<option value="<?php echo $row_ta->id_mr_th_ajaran; ?>"><?php echo $row_ta->th_ajaran; ?></option>
					<?php 
						} 
					}else{
					?>
						<option>Tidak ada data</option>
					<?php 
					}
					?>
				</select>
			</div>
		</div>
			
		<div id="list_siswa"></div>

		<?php 
			echo form_close();
		?>
		
		</div>

		<div id="pindah" style="display:none;">
		<?php 
			echo form_open('bagi_kelas/pindah', array('class' => 'form-horizontal', 'role' => 'form')); 
		?>

		<div class="form-group">
			<label class="col-sm-3 control-label">Kelas</label>
			<div class="col-sm-9">
			<select name="id_mr_kelas" id="kelas_pindah" class="form-control input-sm" <?php if(count($list_kelas_pindah)<1){echo "disabled";}?>>
					<option value="null">- Pilih Kelas -</option>
					<?php 
					if(count($list_kelas_pindah)>0){
						foreach ($list_kelas_pindah as $row_k){ ?>
						<option value="<?php echo $row_k->id_mr_kelas; ?>"><?php echo $row_k->kelas; ?></option>
					<?php 
						}
					}else{
					?>
						<option>Tidak ada data</option>
					<?php 
					}
					?>
				</select>
			</div>
		</div>
		<input type="hidden" name="id_atur_kelas" value="<?php echo $nis = $this->security->xss_clean($this->uri->segment(3));?>"/>
		<div id="list_siswa_pindah"></div>
		<?php
			echo form_close();
		?>
		</div>
	
		
      </div>      
    </div>
  </div>
</div>
<!-- end add siswa modal -->

<div id="page-wrapper">
    <!-- /.row -->
    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <!--<span class="judul-page">Siswa Kelas: <?php $kelas = array_slice($list,0,1); foreach ($kelas as $row_k) {echo $row_k->kelas;}?> Pada Th. Ajaran: <?php $tha = array_slice($list,0,1); foreach ($tha as $row_th) {echo $row_th->th_ajaran;}?> Wali Kelas: <?php $wali_k = array_slice($list,0,1); foreach ($wali_k as $row_wk) {echo $row_wk->nm_pegawai;}?></span> //-->
                    <?php
						foreach ($list_meta as $row_m) {
					?>
					<span class="judul-page">
						Siswa Kelas: <?php echo $row_m->kelas.' - ';?>
						<?php foreach($list_lembaga as $rows){$id_lembaga = $rows->id_lembaga; echo $rows->nama_lembaga; } ?>
						Pada Th. Ajaran: <?php echo $row_m->th_ajaran;?>
						Wali Kelas: <?php echo $row_m->nm_pegawai;?>
					</span>
					<?php
						}
					?>
					<span class="pull-right">
                        <a href="<?php echo htmlspecialchars($_SERVER['HTTP_REFERER']); ?>" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-arrow-left"></span>&nbsp;Kembali</a>
                        <a href="" class="btn btn-warning btn-xs" data-toggle="modal" data-target="#addSiswa"><span class="glyphicon glyphicon-plus"></span>&nbsp;Tambah Siswa</a>
                    </span>
                    <div class="clearfix"></div>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                      <table class="table table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th width="50">#</th>
                                <th width="100">NIS</th>
                                <th>Nama Lengkap</th>
                                <th>TTL</th>
                                <th>Alamat</th>
                            </tr>
                        </thead>
                        <tbody>
						<?php 
						if(count($list)>0){
							$i = 1; 
							foreach ($list as $row) {
						?>										
                            <tr> <a href="<?php echo site_url().'bagi_kelas/kelas/'.$row->id_atur_kelas; ?>"></a>
                                <td><?php echo $i++ ?></td>
                                <td><?php echo $row->nis; ?></td> 
                                <td><?php echo $row->nm_lengkap; ?></td> 
                                <td><?php echo $row->tmp_lahir.', '.date("d-m-Y", strtotime ($row->tgl_lahir)); ?></td>
                                <td>
									<?php echo substr($row->alamat, 0,60); ?> 
									<a href="<?php echo site_url('bagi_kelas/delete/'.$row->id_bagi_kelas);?>" class="btn btn-danger btn-xs pull-right" title="Hapus" onclick="return confirm('Yakin Anda akan menghapus siswa dari kelas ini secara permanen?')"><span class="glyphicon glyphicon-trash"></span></a>
								</td>
							</tr>
						<?php
							}
						}else{
						?>
							<tr>
                                <td colspan="5"><center>Belum ada siswa pada kelas ini.</center></td>
							</tr>
						<?php
						}
						?>
                        </tbody>
                      </table>
                    </div>
                    <div class="clearfix"></div>
                    <center>
                    <?php
                    echo ! empty($pagination) ? '<center><div class="pagination">' . $pagination . '</div></center>' : '';
                    ?>
                    </center>
                </div>
            </div>
        </div>
    </div>
    <!-- /.row -->
<input type="hidden" name="id_atur_kelas" id="atur_kelas" value="<?php echo $nis = $this->security->xss_clean($this->uri->segment(3));?>"/>
<input type="hidden" id="id_lembaga" value="<?php echo $nis = $this->security->xss_clean($this->uri->segment(4));?>" />
<input type="hidden" id="id_th_a" value="<?php echo $this->security->xss_clean($this->uri->segment(5));?>"/>
</div>
<!-- /#page-wrapper -->
<script>
$("#kelas").change(function(){
	var id_mr_kelas = $("#kelas").val();
	var id_mr_th_ajaran = $("#tajar").val();
	var id_atur_kelas = $("#atur_kelas").val();
	var id_lembaga = $("#id_lembaga").val();
		$.ajax({
			type: "POST",
			data: "id_mr_kelas="+id_mr_kelas+"&id_mr_th_ajaran="+id_mr_th_ajaran+"&id_atur_kelas="+id_atur_kelas+"&id_lembaga="+id_lembaga,
			url : "<?php echo site_url(); ?>bagi_kelas/list_siswa",				
			cache: false,
				success: function(msg){
					$("#list_siswa").html(msg);
				}
		});
});
$("#tajar").change(function(){
	var id_mr_kelas = $("#kelas").val();
	var id_mr_th_ajaran = $("#tajar").val();
	var id_atur_kelas = $("#atur_kelas").val();
	var id_lembaga = $("#id_lembaga").val();
		$.ajax({
			type: "POST",
			data: "id_mr_kelas="+id_mr_kelas+"&id_mr_th_ajaran="+id_mr_th_ajaran+"&id_atur_kelas="+id_atur_kelas+"&id_lembaga="+id_lembaga,
			url : "<?php echo site_url(); ?>bagi_kelas/list_siswa",				
			cache: false,
				success: function(msg){
					$("#list_siswa").html(msg);
				}
		});
});
$("#kelas_pindah").change(function(){
	var id_mr_kelas = $("#kelas_pindah").val();
	var id_mr_th_ajaran = $("#id_th_a").val();
	var id_atur_kelas = $("#atur_kelas").val();
	var id_lembaga = $("#id_lembaga").val();
		$.ajax({
			type: "POST",
			data: "id_mr_kelas="+id_mr_kelas+"&id_mr_th_ajaran="+id_mr_th_ajaran+"&id_atur_kelas="+id_atur_kelas+"&id_lembaga="+id_lembaga,
			url : "<?php echo site_url(); ?>bagi_kelas/list_siswa_pindah",				
			cache: false,
				success: function(msg){
					$("#list_siswa_pindah").html(msg);
				}
		});
});
</script>